import { defineStore } from 'pinia';
import { ref } from 'vue';
import { user } from '@/api/user';
export const useUserStore = defineStore(
  'user',
  () => {
    const token = ref('');
    const setToken = (newToken) => {
      token.value = newToken;
    };
    const removeToken = () => {
      token.value = '';
    };
    const userinfo = ref();
    const getUser = async () => {
      const res = await user();
      userinfo.value = res.data.data;
    };
    const setUser = (obj) => {
      userinfo.value = obj;
    };
    return {
      token,
      userinfo,
      setToken,
      removeToken,
      getUser,
      setUser
    };
  },
  {
    persist: {
      enabled: true
    }
  }
);
